<template>
  <div>
    <el-input
      v-model="filterText"
      style="padding=20px"
      placeholder="输入关键字进行查询"/>
    <el-tree
      ref="tree"
      :data="data"
      :filter-node-method="filterNode"
      :props="defaultProps"
      @node-click="handleNodeClick"/>
  </div>
</template>
<script>
import subject from '@/api/subject'
export default {
  data() {
    return {
      filterText: '',
      data: [{
        label: '一级 1',
        children: [{
          label: '二级 1-1',
          children: [{
            label: '三级 1-1-1'
          }]
        }]
      }, {
        label: '一级 2',
        children: [{
          label: '二级 2-1',
          children: [{
            label: '三级 2-1-1'
          }]
        }, {
          label: '二级 2-2',
          children: [{
            label: '三级 2-2-1'
          }]
        }]
      }, {
        label: '一级 3',
        children: [{
          label: '二级 3-1',
          children: [{
            label: '三级 3-1-1'
          }]
        }, {
          label: '二级 3-2',
          children: [{
            label: '三级 3-2-1'
          }]
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    subject.getParents().then(r => {
      this.data = r.data.parent
    })
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true
      return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1// 忽略大小写
    }

  }
}
</script>
